package org.erp.product.strategy.impl;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.annotation.StockLockBatch;
import org.erp.product.domain.dto.DickerDto;
import org.erp.product.domain.dto.TransferDto;
import org.erp.product.infrastructure.mq.service.ProductRabbitService;
import org.erp.product.service.ConnectLogService;
import org.erp.product.strategy.TransferSourceStrategy;
import org.springframework.stereotype.Service;

import java.util.List;

@Log4j2
@Service(value = "WAREHOUSE")
@AllArgsConstructor
public class WarehouseTransferSourceStrategy implements TransferSourceStrategy {

    private final ConnectLogService connectLogService;

    private final ProductRabbitService productRabbitService;


    @StockLockBatch(listField = "dickerDtoList", idField = "stockId")
    @Override
    public void process(TransferDto transferDto) {
        List<DickerDto> dickerDtoList = connectLogService.checkForsake(transferDto.getDickerDtoList());
        productRabbitService.sendTransferMessage(transferDto,dickerDtoList);
    }
}
